from datetime import datetime
from django.db.models import *
from mptt.models import MPTTModel, TreeForeignKey

class Product(Model):
    name=CharField(max_length=256)
    # productID: sku/EAN/serial?
    productType=ForeignKey('ProductType')

    created=DateTimeField()
    modified=DateTimeField()

    def save(self, *args, **kwargs):
        if not self.id: self.created=datetime.now()
        self.modified=datetime.now()
        Model.save(self, *args, **kwargs)

    def __unicode__(self): return self.name

class ProductType(MPTTModel):
    name=CharField(max_length=256)
    parent=TreeForeignKey('self', null=True, blank=True, related_name='children')

    def __unicode__(self): return self.name

    class MPTTMeta:
        order_insertion_by=['name']
